<template>
	<view class="box">
		<form @reset='reset' @submit="submit">
			<view class="top">
				收货人 <input type="text" v-model="add.username" />
			</view>
			<view class="top">
				手机号 <input type="text" v-model="add.userphone" />
			</view>
			<view class="top">
				所在地址 <input type="text" v-model="add.regioncode" />
			</view>
			<view class="top">
				邮政编号 <input type="text" v-model="add.location" />
			</view>
			<view class="top a">
				<text>详细地址</text> <textarea id="" v-model="add.useraddress"></textarea>
			</view>
			<view class="bq">
				标签<checkbox-group name='bq'>
					<checkbox value="家" :checked="add.label==='家'?true:false" /><text>家</text>
					<checkbox value="公司" :checked="add.label==='公司'?true:false" /><text>公司</text>
					<checkbox  value="学校" :checked="add.label==='学校'?true:false" /><text>学校</text>
				</checkbox-group>
			</view>
			<view class="dz">
				<text>设置默认地址</text>
				<switch v-model='add.status' checked="true" @change="" color="#FF6600" />
			</view>
			<view class="tx">
				提醒：每次下单会默认推荐地址
			</view>
			<button class="bc" form-type="submit">保存并设置</button>
			<button form-type="reset">重置</button>
		</form>

	</view>
</template>

<script>
	import {
		addRessadd,
		addreSsedit
	} from '../../request/app.js'
	export default {
		data() {
			return {
				list: [],
				add: {}
			}
		},
		onLoad(options) {
			console.log(options.siteData, '2222222222222');
			this.add = options.siteData ? JSON.parse(options.siteData) : {}
		},

		methods: {
			reset() {},
			submit() {
				console.log(this.add.username);
				if (!this.add.id) {
					// console.log(e, '111');
					// let a = e.detail.value
					addRessadd({
						uid: uni.getStorageSync('userinfo').uid,
						username: this.add.username,
						userphone: this.add.userphone,
						regioncode: this.add.regioncode,
						location: this.add.location,
						useraddress: this.add.useraddress,
						status: this.add.status ? 1 : 0,
						label: this.add.label
					}).then(res => {
						console.log(res, 'fan');
						if (res.data.code == 200) {
							uni.navigateTo({
								url: '../address/address'
							})

						} else {
							uni.showToast({
								title: '请将信息补充完整'
							})
						}
					})
				} 
				else {
					let w = this.add
					console.log(w, '222222');
					addreSsedit({
						id: w.id,
						username: w.username,
						userphone: w.userphone,
						location: w.location,
						useraddress: w.useraddress,
						status: w.status? 1 : 0,
						label: w.label
					}).then(res => {
						console.log(res, '编辑');
						if (res.data.code == 200) {
							uni.navigateTo({
								url: '../address/address'
							})
						}
					})
				}


			}
		}
	}
</script>

<style>
	.box {
		padding: 40rpx;
	}

	.top {
		border-bottom: 1rpx solid #ccc;
		display: flex;
		font-size: 40rpx;
		height: 80rpx;
		margin-top: 50rpx;
		/* padding: 30rpx; */
	}

	.top input {
		margin-left: 40rpx;
	}

	.a {
		height: 300rpx;

	}

	.a textarea {
		width: 500rpx;
		background: #ccc;
	}

	.a text {
		line-height: 300rpx;
	}

	.bq checkbox-group {
		margin-left: 80rpx;
	}

	.bq checkbox-group checkbox {
		margin-left: 30rpx;
	}

	.bq {
		margin-top: 30rpx;
		display: flex;
	}

	.dz {
		display: flex;
		justify-content: space-between;
		height: 200rpx;
		line-height: 200rpx;
	}

	.tx {
		border-bottom: 1rpx solid #ccc;
		margin-bottom: 30rpx;
	}

	.bc {
		background: red;
		color: white;
	}
</style>
